package com.example.cdmuseum.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cdmuseum.R;
import com.example.cdmuseum.base.BaseActivity;
import com.example.cdmuseum.bean.BoutiqueGv;
import com.example.cdmuseum.ui.adapter.BoutiqueHomeListAdapter;

import java.util.LinkedList;
import java.util.List;

import butterknife.BindView;

/**
 * BoutiqueHomeActivity
 * 精品首页
 */
public class BoutiqueHomeActivity4 extends BaseActivity {
    @BindView(R.id.rl_back)
    RelativeLayout back;


    @BindView(R.id.img_icon)
    ImageView img_icon;

    @BindView(R.id.tv_title)
    TextView tv_title;


    @BindView(R.id.tv_show_list)
    TextView tv_show_list;

    private List<BoutiqueGv> mData = null;
    private BoutiqueHomeListAdapter mAdapter = null;
    //
    @BindView(R.id.gv_data)
    GridView list_animal;


    String title;

    int img_id = 0;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_boutique_home;
    }

    @Override
    protected void init() {
        Intent intent = getIntent();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initData();

        title = intent.getStringExtra("title");
        img_id = intent.getIntExtra("index", 0);
        if (img_id != 0) {
            img_icon.setImageResource(img_id);
        } else {
            img_icon.setImageResource(R.drawable.boutique_1);
        }
        tv_title.setText(title);
        tv_show_list.setText(title + "列表");
    }

    public void initData() {
        mData = new LinkedList<BoutiqueGv>();
        mData.add(new BoutiqueGv("“军政府南北议和全权总代表”大印", "民国\n\n唐绍仪\n\n长5.75厘米，宽5.75厘米，高11厘米，厚2.2厘米，重：175.25克。\n\n由印面和印把组成，印把为上大下小的圆柁形，印面为方形。", R.drawable.p5_1));
        mAdapter = new BoutiqueHomeListAdapter((LinkedList<BoutiqueGv>) mData, this);
        list_animal.setAdapter(mAdapter);
        list_animal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(getApplicationContext(), "点击" + i, Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(BoutiqueHomeActivity4.this, BoutiqueHomeDetailActivity.class);
                intent.putExtra("img", mData.get(i).getaIcon());
                intent.putExtra("show_name", mData.get(i).getaName());
                intent.putExtra("description", mData.get(i).getaSpeak());
                intent.putExtra("index", i);
                startActivity(intent);
            }
        });
    }


}